﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Manager_System
{
    public partial class white_process : Form
    {
        string type="";
        main_form form;
        string Interid="";
        string Id = "";
         public white_process(main_form form1)
        {
            type = "添加";
            InitializeComponent();
 
            form = form1;
        }
         public white_process(string interid, string id, string material, string specification, string situation,  main_form form1)
        {
           
             InitializeComponent();
             Interid = interid;//
            type = "修改";
            specification_tb.Text = specification;//
            Id = id.Substring(0, 4) + "/" + id.Substring(4, 2) + "/" + id.Substring(6, 2);//
            steel_dt.Value = Convert.ToDateTime(Id);
            form = form1;//
            this.material_tb.Text = material;//
      
      


            situation_tb.Text = situation;//
 
        }


        private void white_process_Load(object sender, EventArgs e)
        {
            add_white_bt.Text = type.ToString();
            steel_dt.Format = DateTimePickerFormat.Custom; //设置为显示格式为自定义
            steel_dt.CustomFormat = "yyyy-MM-dd";


            this.add_white_bt.Text = type;
        }

        private void add_white_bt_Click(object sender, EventArgs e)
        {
            #region 添加/修改计划
            string sql = "";
            string ID = steel_dt.Text.Substring(0, 4) + steel_dt.Text.Substring(5, 2) + steel_dt.Text.Substring(8, 2);
            if (type.Equals("添加"))
            {
                sql = "insert into T_white_process (time,material,specification,situation) values('" + ID + "','" + material_tb.Text + "','" +specification_tb.Text + "','" + situation_tb.Text + "')";
            }
            if (type.Equals("修改"))
            {
                sql = "update T_white_process set time='" + ID + "',material='" + material_tb.Text + "',specification='" + specification_tb.Text + "',situation='" + situation_tb.Text + "' where InterID='" + Interid + "'";
            }

            if (material_tb.Text.Trim() != String.Empty && specification_tb.Text.Trim() != String.Empty&& situation_tb.Text.Trim() != String.Empty && steel_dt.Value.ToString() != String.Empty)
            {

                DBhelp db = new DBhelp();
                int rs = db.update(sql);
                if (rs == 1)
                {
                    MessageBox.Show(type.ToString() + "成功！");
                }
                else
                {
                    MessageBox.Show(type.ToString() + "失败！");
                }
                db.close();

                form.Refresh_white_process_LV("n");
            }
            else
            {
                MessageBox.Show("请输入相关数值！");
            }
            #endregion
        }

        private void close_bt_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
